package net.kosev.battleships;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ToggleButton;

/**
 * Settings activity
 * 
 * @author Nikola
 *
 */
public class SettingsScreen extends Activity implements OnClickListener {

	/**
	 * Back button component
	 */
	private Button mBack = null;
	
	/**
	 * Toggle button for enabled sound
	 */
	private ToggleButton mSound = null;
	
	/**
	 * Toggle button for enabled vibrations
	 */
	private ToggleButton mVibrate = null;
	
	/**
	 * Toggle button for enabled revealing
	 */
	private ToggleButton mReveal = null;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		mBack = (Button) findViewById(R.id.ButtonBack);
		mBack.setOnClickListener(this);
		
		mSound = (ToggleButton) findViewById(R.id.ToggleSound);
		mSound.setChecked(Config.enabledSound);
		mSound.setOnClickListener(this);
		
		mReveal = (ToggleButton) findViewById(R.id.ToggleReveal);
		mReveal.setChecked(Config.enabledRevealing);
		mReveal.setOnClickListener(this);
		
		mVibrate = (ToggleButton) findViewById(R.id.ToggleVibrate);
		mVibrate.setChecked(Config.enabledVibration);
		mVibrate.setOnClickListener(this);
	}

	/*
	 * (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ButtonBack:
			finish();
			break;
		case R.id.ToggleSound:
			Config.enabledSound = mSound.isChecked();
			Config.save(this);
			break;
		case R.id.ToggleVibrate:
			Config.enabledVibration = mVibrate.isChecked();
			Config.save(this);
			break;
		case R.id.ToggleReveal:
			Config.enabledRevealing = mReveal.isChecked();
			Config.save(this);
			break;
		}
	}

}
